#include<bits/stdc++.h>
using namespace std;
int t,n,a[20],ans;
void dfs(int e,int b,int c,int sum){
    if(e==n+1){
        ans=max(ans,sum);
        return;
    }
    dfs(e+1,e,c,sum+(a[e]==a[b]?a[e]:0));
    dfs(e+1,b,e,sum+(a[e]==a[c]?a[e]:0));
    return;
}
int main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--){
        scanf("%d",&n);
        for(int i=1;i<=n;i++){
            scanf("%d",&a[i]);
        }
        a[0]=-1;
        ans=0;
        dfs(1,0,0,0);
        printf("%d\n",ans);
    }
    return 0;
}
